package teach.aistar.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import teach.aistar.model.entity.Talk;
import teach.aistar.service.ITalkService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
@RequestMapping("/user")
public class PjController {

    @Autowired
    private ITalkService iTalkService;

    @RequestMapping("/pj")
    public String Pj(HttpServletRequest request , HttpSession session)
    {

        String ordersNo= request.getParameter("ordersNo");

        Long secId = Long.valueOf(request.getParameter("secId"));

//        String uName = (String) session.getAttribute("uname");

//        String talkBody = request.getParameter("talkBody");
//
//        Talk talk = new Talk();
//        talk.setDateX(new Date());
//
//        talk.setUserName(uName);
//
//        talk.setTalkBody(talkBody);
//
//        talk.setWebOrderId(Integer.valueOf(id));
           request.setAttribute("secId",secId);

//        int x = iTalkService.insertP(talk);
          request.setAttribute("ordersNo",ordersNo);

//        System.out.println("是否插入成功"+x);



        return "pj";
    }

    @RequestMapping("/addP")
    public String add(HttpSession session,HttpServletRequest request)
    {

        String uName = (String) session.getAttribute("uname");
        String webOrderId = request.getParameter("webOrderId");
        Long productId = Long.valueOf(request.getParameter("productId"));
        String talkBody = request.getParameter("talkBody");
        Talk talk = new Talk();
        talk.setDateX(new Date());

        talk.setTalkBody(talkBody);
        talk.setWebOrderId(webOrderId);
        talk.setUserName(uName);
        talk.setProductId(productId);

        int x = iTalkService.insertP(talk);
        System.out.println("是否插入成功"+x);
        return "pj";
    }

}
